<template>
	<view class="container">
		<u-form :model="form" ref="uForm" label-position="top" :error-type="['toast']">
			<u-form-item label="选择日期" prop="submitDate">
				<u-input v-model="form.submitDate" type="select" @click="show = true"/>
			</u-form-item>
			<u-form-item label="填写金额(元)" prop="amount">
				<u-input v-model="form.amount" type="number"/>
			</u-form-item>
			<u-form-item label="申请事由" prop="content">
				<u-input v-model="form.content" type="textarea"/>
			</u-form-item>
		</u-form>
		<u-button class="action-view" @click="saveClick">保存</u-button>
		<!-- <u-select v-model="show" :list="list" label-name="name" value-name="id" @confirm="confirm"></u-select> -->
		
		<u-picker v-model="show" mode="time" @confirm="confirm"></u-picker>
	</view>
</template>

<script>
	import { addImprest } from '@/api/common.js'
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				form: {
					submitDate: '',
					amount: '',
					content: ''
				},
				rules: {
					submitDate: [{
						required: true,
						message: '请选择日期',
					}, ],
					amount: [{
						required: true,
						message: '请填写金额',
					}, ],
					content: [{
						required: true,
						message: '请填写说明',
					}, ],
				},
				show: false,
			}
		},
		computed: {
			...mapState({
				tchInfo: state => state.user.tchInfo,
			})
		},
		onLoad() {
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			saveClick() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						this.addRecord();
						return;
					}
				});
			},
			
			addRecord() {
				addImprest(this.form).then(res => {
					this.$u.toast('添加成功');
					setTimeout(function(){
						uni.navigateBack({delta:1})
					},1000)
				})
			},
			
			confirm(e) {
				console.log(e);
				this.form.submitDate = `${e.year}-${e.month}-${e.day}`
			},
			
			onNavigationBarButtonTap(event) {
			    uni.navigateTo({
			    	url: '/pages_operate/imprest/list',
			    	events: {
			    		//发布成功
			    		pushSuccessEvent: function(data) {
			    		},
			    	},
			    })
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: $app-page-bg-color;
	}
</style>
<style lang="scss" scoped>
	@import '@/css/u-form.scss';
	
	.container {
		padding-left: 30rpx;
		padding-right: 30rpx;
		display: flex;
		flex-direction: column;
	}

	.children-view {
		width: 10rpx;
		flex: 1;
		display: flex;
		flex-direction: row;
	}
</style>
